import {ref} from "vue"
//猎鹰
export const aMapTrack = (sid,tid,trid) => {
	//插件
	var track = uni.requireNativePlugin('AMap-Track');
	var sid=sid;
	var tid=tid;
	var trackId=trid;
	
	//初始化
	track.init(sid);
	
	track.setOnTrackListener(function(res){
		console.log(res);
		//通过res.type判断回调接口名称, res.data为回调参数数据
		if (res.type == "onQueryTerminalCallback") {
			//that.onQueryTerminalCallback(res.data);
		} else if (res.type == "onStartGatherCallback") {
			
		} else if (res.type == "onStartTrackCallback") {
			startGather();
		} else if (res.type == "onStopTrackCallback") {
			
		} else if (res.type == "onStopGatherCallback") {
			
		}//更多回调接口参考OnTrackListener和OnTrackLifecycleListener
		//http://a.amap.com/lbs/static/unzip/Android_Track_Doc/com/amap/api/track/query/model/OnTrackListener.html
		//http://a.amap.com/lbs/static/unzip/Android_Track_Doc/com/amap/api/track/OnTrackLifecycleListener.html
	});
	
	//配置定位采集周期和上报周期
	var gatherInterval = 2;//定位信息采集周期,单位s,默认2s
	var packInterval = 20; //上报周期，单位s,默认20s
	track.setInterval(gatherInterval, packInterval);
	
	//配置本地缓存大小20M
	track.setCacheSize(20);
	
	//配置定位模式
	track.setLocationMode(1);//HIGHT_ACCURACY = 1;DEVICE_SENSORS = 2;BATTERY_SAVING = 3;
	
	//启动上报
	function startTrack() {
		console.log(sid, tid, trackId,'sid, tid, trackId')
		track.startTrack(sid,tid,trackId);
	}
	
	//停止上报
	function stopTrack() {
		track.stopTrack(sid, tid, trackId);
	}
	//开始搜集数据
	function startGather() {
		track.startGather();
	}
	//停止搜集数据
	function stopGather() {
		track.stopGather();
	}
	startTrack();
}